import React,{Component}from 'react';
import {Input,Button,Form,Select, message} from 'antd';
import http from '../api/http';
const { Option } = Select;
class MySearch extends Component{
    constructor(props){
        super(props)
        this.state={
           searchInfo:{}
        }
    }
    /* serchInfo查询收索 */
    serchInfo=(e)=>{
        e.preventDefault();
        this.props.form.validateFields((err,values) => {
            if (!err) {
                //console.log(values,this.props.info.searchUrl)
                message.success('查询请求成功,更新Table')
                this.props.Back(values)
            }
        });
    }
    /* 添加 */
    addSite=()=>{
        this.props.SearchUpdata('add')
    }
    handleProvinceChange=(info,id)=>{
        this.setState({searchInfo:{id:id,parentId:info.id}})
    }
    render(){
        const { getFieldDecorator } = this.props.form;
        return(
            <div style={{padding:'10px 20px'}}>
                <Form layout="inline" {...http.formItemLayout} style={{width:'100%'}} className='flexlb flex-wrap' onSubmit={this.serchInfo.bind(this)}>
                    <div style={{width:'90%'}}>
                    {this.props.info.info.map((item,index)=>{
                        return(
                            <div key={index} style={{width:'260px',float:'left'}}>
                                {item.type==='input'&&
                                    <Form.Item label={item.label}>
                                        {getFieldDecorator(item.key)(
                                            <Input/>
                                        )}
                                    </Form.Item>
                                }
                                {item.type==='selectOne'&&
                                    <Form.Item key={index} label={item.label}>
                                        {getFieldDecorator(item.key,{initialValue:item.info[0].id})(
                                            <Select allowClear style={{ width: 180 }}  onChange={this.handleProvinceChange.bind(this,item.info[index])}>
                                                {item.info.map((itemTwo,idx)=> (
                                                    <Option key={idx} value={itemTwo.id}>{itemTwo.name}</Option>
                                                ))}
                                            </Select>
                                        )}
                                    </Form.Item>
                                }
                            </div>
                        )
                    })}
                    </div>
                    <Button type="primary" size='default' style={{marginLeft:'10px'}} onClick={this.serchInfo}>查询</Button>
                </Form>
            </div>
        )
    }
}
const MySearchForm = Form.create({ name: 'normal_login' })(MySearch);

export default MySearchForm;